package blog.service.impl;


import blog.dao.ChapterChapterLabelDao;
import blog.pojo.ChapterChapterLabel;
import blog.service.ChapterChapterLabelService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ChapterChapterLabelServiceImpl implements ChapterChapterLabelService {

    @Autowired
    private ChapterChapterLabelDao chapterChapterLabelDao;

    @Override
    public void edit(Integer chapterId, List<Integer> labelIdList) throws Exception{
        ChapterChapterLabel chapterChapterLabel = new ChapterChapterLabel().setChapterId(chapterId);
        chapterChapterLabelDao.delete(new QueryWrapper<>(chapterChapterLabel));
        for(Integer labelId : labelIdList){
            ChapterChapterLabel temp = new ChapterChapterLabel().setChapterId(chapterId).setChapterLabelId(labelId);
            chapterChapterLabelDao.insert(temp);
        }
    }
}
